package userAPI

import (
	"github.com/gin-gonic/gin"
	"go-gin-init/app/models/req"
	"go-gin-init/app/service"
	"go-gin-init/common/ctx"
	"go-gin-init/common/result"
	"go-gin-init/common/xerr"
)

// UserDelete
// @Summary 删除用户
// @Description
// @Tags USER
// @Produce json
// @Security ApiKeyAuth
// @Param id path int true "请求参数"
// @Success 200 {object} result.JsonResult "{"code":200,"data":{},"msg":"SUCCESS"}"
// @Failure 400 {object} result.JsonResult "{"code":200,"data":{},"msg":""}"
// @Failure 500 {string} string "Internal Server Error"
// @Router /user/del/{id} [delete]
func UserDelete(c *gin.Context) {

	var u req.GetCurrentUserReq
	if err := c.ShouldBindUri(&u); err != nil {
		result.ParamErrorResult(c, err)
		return
	}

	if err := ctx.CheckPermissionCtx(u.Id, c); err != nil {
		result.JsonRsp(c, nil, err)
		return
	}

	defaultUserModel := service.NewDefaultUserModel()
	err := defaultUserModel.DeleteUser(u.Id)
	if err != nil {
		result.JsonRsp(c, nil, xerr.NewErrCode(xerr.SERVER_COMMON_ERROR))
		return
	}

	result.JsonRsp(c, nil, nil)
}
